#include <SDL.h>
#include <SDL_mixer.h>
#include <assert.h>
#include "scr_music.h"

SCRMusic::SCRMusic(const std::string& Filename)
	: SCRResource()
	, m_pMusic(NULL)
{
	m_pMusic = Mix_LoadMUS(Filename.c_str());
	if (m_pMusic)
	{
		m_Filename = Filename;
		m_IsValid = true;
	}
}

SCRMusic::~SCRMusic()
{
	if (m_pMusic)
	{
		Mix_FreeMusic(m_pMusic);
	}
}

void SCRMusic::Play()
{
	assert(m_pMusic);

	if (Mix_PlayingMusic() == 0)
	{
		Mix_HaltMusic();
	}

	Mix_PlayMusic(m_pMusic, -1);
}

void SCRMusic::Stop()
{
	if (Mix_PlayingMusic() == 0)
	{
		Mix_HaltMusic();
	}	
}
